package com.ly.proxy615.dynamicsProxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkTest  implements InvocationHandler{
    public static void main(String[] args) {
       /* Idb o = (Idb) Proxy.newProxyInstance(Idb.class.getClassLoader(), IdbImpl.class.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("开始");
                method.invoke(new IdbImpl(), args);
                System.out.println("结束");
                return null;
            }
        });

        o.request("fff");*/


        JdkTest jdkTest = new JdkTest();
        Idb o = (Idb) Proxy.newProxyInstance(Idb.class.getClassLoader(), IdbImpl.class.getInterfaces(), jdkTest);
        o.request("dddd");

    }

   /* private Object jdk;

    public JdkTest(Object jdk) {
        this.jdk = jdk;
    }
*/
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before");
        Object invoke = method.invoke(new IdbImpl(), args);
        System.out.println("after");

        return invoke;
    }
}
